#!/Program Files (x86)/Ruby192/bin/ruby.exe
# listWorkouts.rb

=begin
 # Example code that access the API and outputs all
 # user workouts in a list
=end

require_relative '../includes/runningAhead.rb'

# Please fill in these values
email = 'jon@gullidge.org'
password = 'ferHinka64'

appKey = '7224a8985abe4a718e48518e45a558e2'
appSecret = '2647188727d04786accc408184ca7ff6'
# No need to modify values past here


begin
	p 'Content-Type: text/html'
	p ''
	ra = RunningAhead.new(appKey, appSecret)
	ra.impersonateUser(email, password)
	
	workouts = ra.listWorkouts([ 'Date', 'Distance', 'Duration' ]);

	workouts.each do |workout|
		p 'Date: ' + workout[:date].to_date.to_s + '<br />'
		p 'Distance: ' + workout[:distance] + '<br />' unless workout[:distance].blank?
		p 'Duration: ' + workout[:duration] + '<br />' unless workout[:duration].blank?
		p '<br />'
	end
rescue Exception => e
	puts e.message
	puts e.backtrace
ensure
	# This should always be done. The 'ensure' section is a good place for this!
	ra.destroy
end